{extend name="common@public/base" /}{block name="leftmenu"}{include file="common/leftmenu_zx_apply_index" /}{/block} {block name="head"}
<style>
    #form_container {
        width: 900px;
    }
    
    .tips p {
        padding: 15px;
    }
</style>
{/block}{block name="main"}
<div class="htmltitle">
    <span class="h2" style="margin-right:50px">IP 备案信息填写</span>
</div>
<div class="tips">
    <p class="bg-warning">如表单中的下拉菜单无法正常显示，请更换浏览器访问。比如：<a href="https://www.mozilla.org/zh-CN/firefox/all/">火狐浏览器(firefox)</a>、<a href="https://www.google.cn/intl/zh-CN/chrome/">谷歌浏览器(chrome)</a>。</p>
</div>
<div id="form_container"></div>
{/block} {block name="script"} {include file="common/_form_structure" /} {include file="common/_form_config" /}
<script>
    beianStructure.push(btnStructure);
    var myForm = new dhtmlXForm("form_container", beianStructure);
    myForm.enableLiveValidation(true);
    // 添加 客户名称
    var c_name_struct = formStructure[1].list[6];
    c_name_struct['type'] = 'combo';
    myForm.addItem('ip_bak', c_name_struct, 0, 0);
    $.post("", {
        "_method": "PUT",
        "r": "get_cnames"
    }, function(data) {
        config['cname_check'] = data; // 提交前校验用
        for (var i in data) {
            myForm.getCombo('cName').addOption(i, data[i]);
        }
    });
    myForm.setValidation('cName', function(data) {
        return data in config['cname_check'];
    });
    initCombo();
    myForm.attachEvent("onChange", onChangeHandler);
    myForm.getCombo("cName").attachEvent("onChange", function(value, text) {
        if (sessionStorage.getItem('ipbeian_cName') != value) {
            myForm.forEachItem(function(name){
                initCombo();
                myForm.setItemValue(name, '');
            });
            sessionStorage.setItem('ipbeian_cName', value);
            $.post("", {
                "_method": "PUT",
                "r": "get_detail",
                "id": value
            }, function(_data) {
                for (var i in _data["extra"]) {
                    _data[i] = _data["extra"][i];
                }
                delete _data["extra"];
                myForm.loadStruct({
                    data: _data
                });
            });
        }
    });
    myForm.attachEvent("onButtonClick", function(id) {
        if (id == "commit") {
            if (myForm.validate()) {
                var num = removeSpace();
                if (num > 0) {
                    dhtmlx.alert("已自动去除<b class='text-danger'>" + num + "</b>个字段中的空格，请核对后再次提交。<br>下次请注意不要录入空格，谢谢。");
                    return;
                }
                var myData = myForm.getFormData();
                for (var i in myData) {
                    if (typeof(myData[i]) != "undefined") {
                        // 去空格
                        myData[i] = String(myData[i]).replace(/ /g, "");
                    }
                }
                $.post("", myData, function(data) {
                    data.code == 1 && dhtmlx.alert({
                        title: "&nbsp;",
                        text: "操作成功。已自动发送 idc 备案邮件。",
                        callback: function() {
                            history.go(0);
                        },
                    });
                    data.code == 0 && dhtmlx.alert({
                        type: "alert-error",
                        title: data.msg, // 返回始终为 null
                        text: data.data
                    });
                });
            } else {
                dhtmlx.alert({
                    type: "alert-error",
                    title: "数据验证有误",
                    text: "请检查填写是否完整或格式类型是否正确。"
                });
            }
        }
        if (id == "test") {
            myForm.setFormData({
                instanceId: "91001234567",
                cPerson: "cPersion",
                cPhone: 1,
                cEmail: "1@1.com",
                unitProperty: 5,
                unitCategory: 13,
                industryCategory: 3,
                credential: 2,
                credentialnum: "112345zzz6789",
                county: 211202,
                zipCode: 112000,
                appServType: 4,
                securityPerson: "cPersion",
                securityPersonID: "123456199912120123",
                securityPhone: 11,
                securityEmail: "11@1.com",
            });
        }
    });
</script> {/block}